package com.ohuang.myapp.provider;

import com.ohuang.baseapp.utils.HiLogUtil;
import com.ohuang.baseapp.utils.ToastUtils;
import ohos.agp.components.*;
import ohos.agp.components.element.Element;
import ohos.app.Context;

import java.util.List;

public class ImgProvider extends PageSliderProvider {
    List<Integer> list;
    Context context;


    public ImgProvider(List<Integer> list,Context context) {
        this.list = list;
        this.context=context;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int i) {
        Image image = new Image(context);
        image.setPixelMap(list.get(i));
        image.setLayoutConfig(
                new StackLayout.LayoutConfig(
                        ComponentContainer.LayoutConfig.MATCH_PARENT,
                        ComponentContainer.LayoutConfig.MATCH_PARENT
                )
        );

        componentContainer.addComponent(image);

        return image;
    }

    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int i, Object o) {
        componentContainer.removeComponent((Component) o);

    }

    @Override
    public boolean isPageMatchToObject(Component component, Object o) {
        return true;
    }


}
